import http from "@/utils/request";
import { getMenuTree } from "./site";
// import * as product from "./product";

//登录
export const login = ({ username, password }) => {
  return http.post("/token-auth/", { username, password });
};
//注册
export const register = ({ nickname, username, password }) => {
  return http.post("/user/", { nickname, username, password });
};
// 登出
export const logout = () => http.get("/logout");

//获取当前正在登录的用户信息
export const user = () => http.get("/user/");

//商品类别
export const category = () => http.get("/category/");
//创建商品 body是一个对象类型数据  body中必须存在name字段
export const createcategory = (body) => http.post("/category/", body);

//修改个人信息
// userinfo 后期用户传入的数据  必须包含id  可能包含{username,nickname,phone,email}
export const edituser = (userinfo) =>
  http.put(`/user/${userinfo.id}/`, userinfo);
//修改密码
export const editpassword = (password) =>
  http.post("/user/reset_password/", password);

//获取商品列表
export const productlist = (params) => http.get("/product/", { params });

//订单列表
export const order_list = () => http.get("/admin/order/");
//角色管理
export const role = () => http.get("/role/");

//上传图片
export const imageUpload = (body) => http.post(`/image/`, body);
//用户列表
export const userlist = (params) => http.get("/admin/user/", { params });
//编辑商品
export const editcategory = (body) => http.put(`/category/${body.id}/`, body);
//删除商品
export const deletecategory = (body) =>
  http.delete(`/category/${body.id}/`, body);
//操作记录
export const actionList = (params) => http.get("/action/", { params });
//创建商品 CreateBaseView
export const createproduct = (body) => http.post("/product/", body);
//更新商品  /product/:id/  CreateDescView
//上传商品图片  /product-image/
//获取所属类别
export const all = () => http.get("/category/all/");

// 注册  登出   获取
export default {
  getMenuTree,
  login,
  logout,
  register,
  user,
  category,
  edituser,
  editpassword,
  productlist,
  order_list,
  role,
  createcategory,
  editcategory,
  imageUpload,
  userlist,
  deletecategory,
  actionList,
  createproduct,
  all,
};
